
#ifndef Velyn_Object_h
#define Velyn_Object_h

#include <string>

#include "tgaload.h"
#include "Drawable.h"
#include "MaterialManager.h"
#include "MeshRenderer.h"

// TODO:
// Model -> Subdivisions::SubdivisionSurface -> Rock
// or Surface -> Subdivisions::SubdivisionSurface -> Rock
// model consists of mesh, material, and a texture 
// Subdivisions are only done on the SubdivisionSurface
// Displacements are only done on Rock
// Scenes -> contain geometry, viewpoint, texture, lighting, and shading (materials?)

namespace Velyn {
    
    // TODO: call this model or surface
    class PolygonMesh {

    protected:

        TriangleMesh* mesh;
        string texture;
        string material;
        
        void createMesh() {
            mesh = new TriangleMesh();
            
            Drawable drawable(Drawable::DUELPYRAMID);
            drawable.draw(mesh);
        }
        
    public:
        
        PolygonMesh(string texture, string material) {
            this->texture = texture;
            this->material = material;
            
            createMesh();
        }
        
        ~PolygonMesh() {
            delete mesh;
        }
        
        void render() {
            MeshRenderer::getInstance()->render(mesh);
        }
        
        void bindTexture() {
            char* t = (char*)malloc(sizeof(char)*(texture.length()+1));
            strcpy(t, texture.c_str());
            
            glEnable(GL_TEXTURE_2D);
            tgaLoadAndBind(t, NULL);
        }
        
        void unbindTexture() {
            // !!!: 1 or 2 will unbind a texture
            
            // 1 
            glDisable(GL_TEXTURE_2D);
            
            // 2 
            // glBindTexture(GL_TEXTURE_2D, NULL);
        }
        
        void useMaterial() {
            MaterialManager::getInstance()->apply(material);
        }
        
        void resetMesh() {
            delete mesh;
            createMesh();
        }
        
    };
    
}

#endif
